//
//  ProcessesDataSource.m
//  HypERLtrace
//
//  Created by Vladimir Sarpe on 19/08/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "ProcessesDataSource.h"

@implementation ProcessesDataSource

- (id)init {
	if (self = [super init]) {
		//init code here
	} 
	return self;
}

#define GET_CHILDREN NSArray *children; \
if (!item) \
    children = dataSource; \
else \
    children = [item objectForKey:@"child"]; \

- (id)outlineView:(NSOutlineView*)outlineView child:(NSInteger)index ofItem:(id)item {
	GET_CHILDREN;
	if ((!children) || ([children count] <= index))
		return nil;
	return [children objectAtIndex:index];
}

- (BOOL)outlineView:(NSOutlineView*)outlineView isItemExpandable:(id)item {
	GET_CHILDREN;
	if ((!children) || ([children count] < 1))
		return NO;
	return YES;
}

- (NSInteger)outlineView:(NSOutlineView*)outlineView numberOfChildrenOfItem:(id)item {
	GET_CHILDREN;
	return [children count];
}

- (id)outlineView:(NSOutlineView*)outlineView objectValueForTableColumn:(NSTableColumn*)tableColumn byItem:(id)item {
	return [item objectForKey:[tableColumn identifier]];
}

- (void) updateData:(NSArray*) data {
	dataSource = data;
}

@end
